<?php
defined('IN_MAIN') or exit('Invalid Access!');

function get_all_subcat_by_maincat($in_parent_id=0){
	global $vars;
	$db=$vars["db"];
	$cur_node=$parent_id=$in_parent_id;
	$ci=0;
	do{
		if(!$rs[$cur_node]){
			$sql="select * from $db->product_category where parent_id='$parent_id' order by title";
			$rs[$cur_node]=mysql_query($sql);
			$rs_cur_record[$cur_node]=0;
		}
		if($rs[$cur_node] && mysql_num_rows($rs[$cur_node])>$rs_cur_record[$cur_node]){
			$connector="";
			for($i=0;$i<$cur_node;$i++){
				$connector.=($i!=($cur_node-1)? "&nbsp;&nbsp;&nbsp;&nbsp;" : "&nbsp;|-->");
			}
			$catid=mysql_result($rs[$cur_node], $rs_cur_record[$cur_node], "id");
			$r_cat[$ci]["id"]=$catid;
			$r_cat[$ci]["title"]=mysql_result($rs[$cur_node], $rs_cur_record[$cur_node], "title");
			$r_cat[$ci]["c"]=$connector;
			$ci++;
			$parent_id=$catid;
			$cur_node++;
		}else{
			$rs[$cur_node]="";
			$cur_node--;                     
			$rs_cur_record[$cur_node]++;
		}
	}while($rs[0] && $rs_cur_record[0]<mysql_num_rows($rs[0]));
	$result=$r_cat;
	return $result;
}
?>